<?php
// +----------------------------------------------------------------------
// | Fengli [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.yanyongwang.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 风黎 < 1280246895@qq.com >
// +----------------------------------------------------------------------


namespace app\admin\controller;

use \think\Cache;
use \think\Controller;
use think\Loader;
use think\Db;
use \think\Cookie;
use app\admin\controller\Permissions;
use think\Validate;

/**
 * 用户控制器
 * Class Users
 * @package app\admin\controller
 */
class Users extends Permissions
{
    /**
     *用户主页
     */
    public function index()
    {
        $model                  = new \app\common\model\Users();

        $where                  = array();
        $param                  = request()->param();
        if(request()->has('nickname') && !empty($param['nickname'])){
            $where['nickname']     = ['like',"%{$param['nickname']}%"];
        }
        $users                  = !count($where) ? $model->where($where)->order('id desc')->paginate(config('paginate.list_rows'))
            : $model->where($where)->order('id desc')->paginate(config('paginate.list_rows'),false,['query'=>$param]);
        $this->assign('users',$users);

        return $this->fetch();
    }

    /**
     * 成绩管理
     */
    public function grade()
    {
        $model                  = new \app\common\model\AnswerRecord();

        $where                  = array();
        $param                  = request()->param();
        if(request()->has('nickname') && !empty($param['nickname'])){
            $where['u.nickname']     = ['like',"%{$param['nickname']}%"];
        }
        $users                  = !count($where) ? $model->alias('ar')->join('users u','ar.user_id=u.id','LEFT')->field(['ar.*','u.head_url','u.nickname'])->where($where)->order('id desc')->paginate(config('paginate.list_rows'))
            : $model->alias('ar')->join('users u','ar.user_id=u.id','LEFT')->field(['ar.*','u.head_url','u.nickname'])->where($where)->order('id desc')->paginate(config('paginate.list_rows'),false,['query'=>$param]);
        $this->assign('users',$users);
        return $this->fetch();
    }
}